/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.controller;

import br.com.documentar.interfacee.InterfaceController;
import br.com.documentar.model.AssociarTabelaVersaoModel;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Santos
 */
public class AssociarTabelaVersaoController implements InterfaceController<AssociarTabelaVersaoModel> {

    br.com.documentar.DAO.AssociarTabelaVersaoDAO dao = new br.com.documentar.DAO.AssociarTabelaVersaoDAO();

    @Override
    public AssociarTabelaVersaoModel getModel() {
        return new br.com.documentar.model.AssociarTabelaVersaoModel();
    }

    @Override
    public DefaultTableModel insertTableModel(AssociarTabelaVersaoModel model) {
        model.getModelTable().setNumRows(0);
        for (br.com.documentar.model.AssociarTabelaVersaoModel p : dao.getDados(model)) {
            model.getModelTable().addRow(new Object[]{
                p.getProduto().getCodigo() + " - " + p.getProduto().getNome(),
                p.getTabela().getCodigo() + " - " + p.getTabela().getNome(),
                p.getVersao().getCodigo() + " - " + p.getVersao().getNome(),
                p.getTableSpace(), p.getTemporaria(), p.getDono(), p.getAcao(),
                p.getAtivo(), p.getTipoBanco(), p.getNomeBanco(), p.getSql()});
        }
        return model.getModelTable();
    }

    @Override
    public DefaultTableModel getDadosTableModel(AssociarTabelaVersaoModel model) {
        return insertTableModel(model);
    }

    @Override
    public boolean setDados(AssociarTabelaVersaoModel model) {
        return dao.setDados(model);
    }

    @Override
    public DefaultComboBoxModel getDadosComboBoxModel(AssociarTabelaVersaoModel model) {
        return insertComboBoxModel(model);
    }

    @Override
    public DefaultComboBoxModel insertComboBoxModel(AssociarTabelaVersaoModel model) {
        for (br.com.documentar.model.AssociarTabelaVersaoModel p : dao.getDados(model)) {
            //model.getModelComboBox().addElement(p.getCodigo() + " - " + p.getNome());
        }
        return model.getModelComboBox();
    }

    public List<AssociarTabelaVersaoModel> getDados(AssociarTabelaVersaoModel model) {
        return dao.getDados(model);
    }
}
